//
//  SearchPage_Vm.swift
//  Pods
//
//  Created by eme on 2017/3/29.
//
//

import RxSwift
import NetWorkCore
import SwiftyJSON
import UtilCore
/*
 owner:cy
 update:2017年03月29日09:03:36
 info: 搜索vm
 */
class SearchPage_Vm :Base_Vm {
    
    /// 表示正在刷新中
    let loading = ActivityIndicator()
    /*
     接收返回的数据
     */
    /// 返回首页数据
    let keyItems = Variable<[String]>([])
    init(refreshTriger: Observable<Void>) {
        super.init()
        refreshTriger
            .map{ HomePageApi.seachIndex }
            .emeRequestApiForRegJson(loading)
            .subscribe(onNext: {[unowned self] (result) in
                switch result {
                case .success(let data):
                    var relArr:[String] = []
                    if let items = data.array {
                        for item in items {
                            if let tempValue = item.string {
                                relArr.append(tempValue)
                            }
                        }
                    }
                    self.keyItems.value = relArr
                case .failure(let error):
                    self.error.onNext(error)
                }
            }).disposed(by: disposeBag)
    }
}
